[id].vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <Detail_news v-if="routeType == 1"></Detail_news>
  10. <!-- 商品详情 -->
  11. <Detail_goods v-if="routeType == 2"></Detail_goods>
  12. <!-- 列表页广告一 -->
  13. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  14. <!-- 页面底部 -->
  15. <HomeFoot1></HomeFoot1>
  16. </template>
  17. <script setup>
  18. //1.页面依赖 start ---------------------------------------->
  19. import { onMounted } from 'vue'
  20. import Detail_goods from '~/components/goods/detail_sec.vue';
  21. import Detail_news from '~/components/news/detail_sec.vue';
  22. //1.页面依赖 end ---------------------------------------->
  23. //2.页面路径 start ---------------------------------------->
  24. const route = useRoute();
  25. const articleId = parseInt(route.params.id);
  26. const targetSegment = getRoutePath(2);
  27. let routeType;
  28. //通过导航路径反向查询导航id
  29. const getRouteType = await requestDataPromise('/web/getWebsiteRoute', {
  30. method: 'GET',
  31. query: {
  32. 'pinyin': targetSegment,
  33. },
  34. });
  35. // console.log('targetSegment', getRouteType);
  36. if (getRouteType.code == 200) {
  37. routeType = getRouteType.data.type
  38. } else {
  39. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  40. console.log("错误位置:通过url路径查询导航池id")
  41. console.log("后端错误反馈:", getRouteType.message)
  42. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  43. }
  44. //2.页面路径 end ---------------------------------------->
  45. //5.广告 start ---------------------------------------->
  46. let adImg1 = ref([]);
  47. let adImg2 = ref([]);
  48. onMounted(async () => {
  49. const { $webUrl, $CwebUrl } = useNuxtApp();
  50. //广告1
  51. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0001`
  52. const responseAd1 = await fetch(url, {
  53. headers: {
  54. 'Content-Type': 'application/json',
  55. 'Userurl': $CwebUrl,
  56. 'Origin': $CwebUrl
  57. }
  58. });
  59. const resultAd1 = await responseAd1.json();
  60. adImg1.value = resultAd1.data[0];
  61. //广告2
  62. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0002`
  63. const responseAd2 = await fetch(url2, {
  64. headers: {
  65. 'Content-Type': 'application/json',
  66. 'Userurl': $CwebUrl,
  67. 'Origin': $CwebUrl
  68. }
  69. });
  70. const resultAd2 = await responseAd2.json();
  71. adImg2.value = resultAd2.data[0];
  72. })
  73. //5.广告 end ---------------------------------------->
  74. //6.设置seo信息 start---------------------------------------->
  75. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  76. method: 'GET',
  77. query: {
  78. 'articleid': articleId
  79. },
  80. });
  81. if (setData.code == 200) {
  82. let seoTitle = setData.data.title;
  83. let seoDescription = setData.data.introduce;
  84. let seoKeywords = setData.data.keyword;
  85. let seoSuffix = setData.data.suffix;
  86. let seoName = setData.data.website_name;
  87. useSeoMeta({
  88. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  89. meta: [
  90. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  91. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  92. ]
  93. });
  94. } else {
  95. console.log("获取广告数据失败!", setData.message)
  96. }
  97. //6.设置seo信息 end---------------------------------------->
  98. </script>
  99. <style lang="less" scoped>
  100. @import url('@/assets/css/detail.less');
  101. </style>